//
//  HJPayBillModel.m
//  KaiChat
//
//  Created by lx on 2023/12/22.
//

#import "HJPayBillModel.h"

@implementation HJPayBillModel


MJLogAllIvars
 
+ (HJPayBillModel *)modelWithMessageModel:(HJChatMessageModel *)messageModel {
    NSDictionary *msgDict = [messageModel.msg mj_JSONObject];
    NSDictionary *dict = msgDict[@"content"];
            
    if (![dict isKindOfClass:NSDictionary.class]) return nil;
    
    HJPayBillModel *model = [[HJPayBillModel alloc] init];
    model.title = dict[@"title"];
    model.timestamp = messageModel.timestamp;
    model.payTimestamp = dict[@"time"];
    
    NSString *payTime = [[NSDate dateWithTimeIntervalSince1970:[model.payTimestamp integerValue] / 1000] stringWithFormat:@"yyyy/MM/dd HH:mm"];
    model.content = [NSString stringWithFormat:@"%@\n%@", dict[@"content"], payTime];
    model.productName = dict[@"goods_name"];
    model.orderId = toString(dict[@"order_id"]);
    model.scene = [dict[@"scene"] intValue];
    model.url = dict[@"url"];
    model.clickEvent = [dict[@"click_event"] intValue];
    model.iconName = [self getIconDict][@(model.scene)];
    model.msg = messageModel.msg;
    UIFont *descFont = UIFontMake(12);
    CGSize textSize = [model.content getStringSizeWithWidth:KScreenWidth - leftRightMargin * 2 - 30 font:descFont];
    textSize = CGSizeMake(ceil(textSize.width), ceil(textSize.height));

    model.height = textSize.height + 36 + 50;
    if (model.clickEvent == 102 || model.clickEvent == 200) {
        model.height += 30;
    } else {
        model.height += 13;
    }
    return model;
}

static NSDictionary *_iconDict;
+ (NSDictionary *)getIconDict {
    if (!_iconDict) {
        _iconDict = @{
            @1: @"payIcon2",
            @2: @"payIcon5",
            @3: @"payIcon4",
            @4: @"payIcon3",
            @5: @"payIcon3",
            @6: @"payIcon5",
            @7: @"payIcon4",
            @8: @"payIcon2",
            @9: @"payIcon5",
            @10: @"payIcon1",
            @11: @"payIcon5",
            @12: @"payIcon1",
            @13: @"payIcon2",
            @14: @"payIcon1",
            @15: @"payIcon5",
            @16: @"payIcon2",
            @17: @"payIcon5",
            @18: @"payIcon4",
        };
    }
    return _iconDict;
}


@end
